package com.yanqu.road.server.channelserver.cmd.activity;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.AutoSendRewardProto;
import com.yanqu.road.server.channelserver.cmd.ChannelCommand;
import com.yanqu.road.server.channelserver.logic.ChannelMessageHelper;
import com.yanqu.road.server.cmd.activity.autoreward.rank.BaseChannelRank;
import com.yanqu.road.server.cmd.activity.autoreward.rank.CrossRankFactory;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.N_CROSS_AUTO_SEND_USER_RANK_LIST, desc = "")
public class ChannelActivityUserRankListCmd extends ChannelCommand {

    private int activityId;
    private int activityType;
    private int childType;
    private int channelId;
    private long serverId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        AutoSendRewardProto.NoticeChannelUserRankMsg msg = AutoSendRewardProto.NoticeChannelUserRankMsg.parseFrom(packet.getBytes());
        activityId = msg.getActivityId();
        activityType = msg.getActivityType();
        childType = msg.getChildType();
        channelId = msg.getChannelId();
        serverId = msg.getServerId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        BaseChannelRank crossRank = (BaseChannelRank)CrossRankFactory.getCrossRank(activityId, activityType, childType);
        AutoSendRewardProto.CrossUserRankMsg.Builder msg = null;
        if (crossRank != null) {
            msg = crossRank.getCrossUserRankMsg(channelId, serverId);
        }
        if (msg == null) {
            msg = AutoSendRewardProto.CrossUserRankMsg.newBuilder();
            msg.setActivityId(activityId);
        }
        ChannelMessageHelper.sendGamePacket(GameProtocol.S_CROSS_ACTIVITY_AUTO_SEND_USER_REWARD, msg, channelId, serverId, 0);
    }

    @Override
    public void sendData() {

    }
}
